import { Body, Controller, Get, HttpCode, Post } from '@nestjs/common';
import { AppService } from './app.service';
import { SQLDto } from './sql.dto';

@Controller('/api')
export class AppController {
  constructor(private readonly appService: AppService) {}

  @Post('/DB/DoFunc')
  @HttpCode(200)
  async DoFunc(@Body() sqlDto: SQLDto) {
    let errCode = 0;
    let errMsg = '';
    let data = [];

    try {
      data = await this.appService.query(sqlDto);
    } catch (error) {
      errCode = 1;
      errMsg = error.message;
    }

    return { errCode, errMsg, data };
  }

  @Get('/time')
  getTime() {
    return { errCode: 0, errMsg: '', data: new Date() };
  }
}
